package com.example.mqttclient;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

import java.io.IOException;

public class WeatherUtils {
    private static final String API_KEY = "SHvayEL-w-_Y0c4bm";
    private static final String API_URL = "https://api.seniverse.com/v3/weather/now.json?key=" + API_KEY + "&location=广东中山&language=zh-Hans&unit=c";

    public static String getWeatherInfo() {
        OkHttpClient client = new OkHttpClient();
        Request request = new Request.Builder()
                .url(API_URL)
                .build();
        try {
            Response response = client.newCall(request).execute();
            if (response.isSuccessful()) {
                return response.body().string();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
